package net.sxnic.ugr.permission.action;
/**
 * @version $Revision$
 * @author 吕盛槐 create 2011-10-04
 */
import net.sxinfo.core.entity.EntityAlreadyExistsException;
import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.permission.Permission;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@SuppressWarnings("serial")
public class Create extends UgrActionSupport {
	
	private static Logger logger = LoggerFactory.getLogger(Create.class);

    private Permission permission;
	
	private String menu;
	
	 
 
	public String execute() throws Exception {
       

        try {
        	 checkRoles(Permission.SYSTEM_ADMIN);
        	 
    			// 角色
//    			if (StringUtils.isBlank(menu)) {
//    				permission.getMenus().clear();
//    				 
//    			} else {
//    				 
//    				String[] menus = StringUtils.split(menu, ",");
//    				permission.getMenus().clear();
//    				Menu m = null;
//    				for (String rr : menus) {
//    					m = authorizationManager.getMenu (rr.trim());
//    					logger.debug("menu id :" + m.getId() + " , Permission id :"
//    							+ permission.getId());
//
//    					permission.getMenus().add(m);
//    					 
//    				}
//    				//user.setRoleCodes(StringUtils.removeEnd(tempCodes, ","));
//    			} 

        	
            this.authorizationManager.createPermission(permission);
            authorizationManager.updatePermission (permission);

        } catch (EntityAlreadyExistsException eaee) {
//            addActionError(getText("security.error.permissionExists",
//                new String[] { permission.getUrl() }));

            return INPUT;
        }

        // 保存成功信息并转向
        msg="createSuccess";

        return SUCCESS;
    }
	
	 public Permission getPermission() {
			return permission;
		}


		public void setPermission(Permission permission) {
			this.permission = permission;
		}


		public String getMenu() {
			return menu;
		}


		public void setMenu(String menu) {
			this.menu = menu;
		}

    
}
